﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using MS.BasicData.Infrastructure;
using MS.BasicData.Read.API.Applications.Permissionss;

namespace MS.BasicData.Read.API.Controllers
{
    /// <summary>
    /// 权限控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class PermisController : ControllerBase
    {
        private readonly IMediator _mediator;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="mediator"></param>
        public PermisController(IMediator mediator)
        {
            _mediator = mediator;
        }
        /// <summary>
        /// 权限信息添加
        /// </summary>
        /// <param name="add"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<ApiRestult> CreatePermisInfo(CreatePermiRequestModel add)
        {
            return _mediator.Send(add);
        }

        /// <summary>
        /// 权限信息删除
        /// </summary>
        /// <param name="delete"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<ApiRestult> DeletePermis(DeletedRequestModel delete)
        {
            return await _mediator.Send(delete);
        }

        /// <summary>
        /// 权限信息更新
        /// </summary>
        /// <param name="update"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiRestult> UpdatePermis(UpdatePermiRequestModel update)
        {
            return await _mediator.Send(update);
        }

        /// <summary>
        /// 权限信息列表
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiRestult> GetPermisList([FromQuery]ListPermiRequestModel list)
        {
            return await _mediator.Send(list);
        }
        /// <summary>
        /// 获取当前用户的树形权限列表
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiRestult> GetTreePermissionList([FromQuery]GetTreePermissionListRequestModel command)
        {
            return await _mediator.Send(command);
        }
    }
}
